<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>props的基本使用方法</title>
</head>
<body>
  <!-- 准备一个容器 -->
  <div id="test"></div>
  <div id="test1"></div>
  <div id="test2"></div>

  <!-- 导入react包 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../js/babel.min.js"></script>
  <script type="text/javascript" src="../js/prop-types.js"></script>

  <script type="text/babel">
  // // 创建函数式组件
  function Person(props){
    const { name, age, sex } = props
    return (
        <div>
          <ul>
            <li>姓名: { name }</li>
            <li>性别: { sex }</li>
            <li>年龄: { age }</li>
          </ul>
        </div>
      )
  }
  // 对标签属性进行必要性以及类型的限制
  Person.propTypes = {
    name: PropTypes.string.isRequired,  // 限制string类型以及必填性
    age: PropTypes.number,
    sex: PropTypes.string,
  }
  
  // 赋予标签属性默认值
  Person.propTypes = {
    sex: "-未知-",
    age: 18
  }

  // 渲染组件到页面
  ReactDOM.render(<Person name="jack" age={100} sex="女"/>, document.getElementById('test'))
  </script>

</body>

</html>